<?php

namespace App\Http\Controllers\Act;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\Eloquent\Act\TopicRepository as Topic;
use App\Repositories\Eloquent\Act\QuestionRepository as Question;
use App\Repositories\Eloquent\Act\JoinRepository as Join;
/**
 * Class LoginController
 * @package App\Http\Backend\Controllers
 */
class TopicController extends Controller
{
    /**
     * @var Administrator
     */
    protected $topic, $question, $join;

    public function __construct(Topic $topic,Question $question, Join $join)
    {
        parent::__construct();

        $this->topic = $topic;

        $this->question = $question;

        $this->join = $join;
    }


    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $topics = $this->topic->index()->paginate(60);

        return view($this->view, compact('topics'));
    }


    public function create()
    {
        return view($this->view);
    }


    public function store(Request $request)
    {
        return $this->topic->store($request);
    }


    public function edit($id)
    {
        $topic = $this->topic->show($id);

        if ($topic instanceof JsonResponse && $topic->getStatusCode() === 404) {
            return abort('404');
        }

        return view($this->view, compact('topic'));
    }


    public function update(Request $request, $id)
    {
        return $this->topic->renew($request, $id);
    }

    public function view($id)
    {
        $topic = $this->topic->show($id);

        if ($topic instanceof JsonResponse && $topic->getStatusCode() === 404) {
            return abort('404');
        }

        return view($this->view, compact('topic'));
    }


    public function lists()
    {
        $joins = $this->join->lists();

        return view($this->view, compact('joins'));
    }

}
